package com.edu.exam.enums;

/**
 * 安排状态枚举
 * 
 * @author S-01 Module Designer
 * @version 2.0
 * @since 2025-11-10
 */
public enum ArrangementStatus {
    PENDING("pending", "待处理"),
    IN_PROGRESS("in_progress", "处理中"),
    COMPLETED("completed", "已完成"),
    FAILED("failed", "失败"),
    CANCELLED("cancelled", "已取消"),
    PARTIAL("partial", "部分完成");

    private final String code;
    private final String description;

    ArrangementStatus(String code, String description) {
        this.code = code;
        this.description = description;
    }

    public String getCode() {
        return code;
    }

    public String getDescription() {
        return description;
    }
    /**
     * 根据代码查找枚举值
     *
     * @param code 枚举代码
     * @return 对应的枚举值
     * @throws IllegalArgumentException 如果代码不存在
     */
    public static ArrangementStatus fromCode(String code) {
        for (ArrangementStatus status : ArrangementStatus.values()) {
            if (status.code.equals(code)) {
                return status;
            }
        }
        throw new IllegalArgumentException("Unknown arrangement status code: " + code);
    }
    /**
     * 根据描述查找枚举值
     *
     * @param description 枚举描述
     * @return 对应的枚举值
     * @throws IllegalArgumentException 如果描述不存在
     */
    public static ArrangementStatus fromDescription(String description) {
        for (ArrangementStatus status : ArrangementStatus.values()) {
            if (status.description.equals(description)) {
                return status;
            }
        }
        throw new IllegalArgumentException("Unknown arrangement status description: " + description);
    }

    @Override
    public String toString() {
        return description;
    }
}